import { defineStore } from 'pinia';
import { ref } from 'vue';

export const useTeamFormStore = defineStore('teamForm', () => {
  // 定义表单的默认值
  const defaultForm = {
    teamName: '',
    image: '',
    teamDesc: '',
    maxMember: 0,
    type: 0,
    teamPassword: '',
    isJoin: 0,
    isFound: 0,
    geoX: 0,
    geoY: 0,
    isLimit: 0,
    beginTime: '',
    endTime: '',
    tags: []
  };

  // 用 ref 创建响应式的表单状态
  const teamForm = ref({ ...defaultForm });

  // 重置表单
  const resetTeamForm = () => {
    teamForm.value = { ...defaultForm };
  };

  // 设置表单数据
  const setTeamForm = (data) => {
    teamForm.value = { ...defaultForm, ...data }; // 合并默认值和新数据
  };

  // 获取表单数据
  const getTeamForm = () => {
    return teamForm.value;
  };

  return { teamForm, resetTeamForm, setTeamForm, getTeamForm };
});
